package com.qingcloud.adminbackend.utils;

import com.qingcloud.adminbackend.entity.sysstation.SysStationEquipment;
import org.apache.poi.ss.usermodel.Cell;

import java.util.List;
import java.util.Random;

public class StringUtil {

    public static final String SOURCES =
            "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";

    public static String generateString(int length) {
        Random random = new Random();
        char[] text = new char[length];
        for (int i = 0; i < length; i++) {
            text[i] = SOURCES.charAt(random.nextInt(SOURCES.length()));
        }
        return new String(text);
    }


    public static String objectString(Object object) {
        if (object != null) {
            return String.valueOf(object);
        }
        return "";
    }

    public static float objectToFloat(Cell object) {
        if (object != null) {
            return (float) Double.parseDouble(String.valueOf(object));
        }
        return 0;
    }

    public static float doubleToFloat(double object) {
        return (float) object;
    }

    public static String listToString(List<String> ids) {
        String equipmenIdJson = "[";
        for (String id : ids) {
            equipmenIdJson += id + ",";
        }
        equipmenIdJson = equipmenIdJson.substring(0, equipmenIdJson.length() - 1) + "]";
        return equipmenIdJson;
    }

    public static String objectToString(List<SysStationEquipment> SysStationEquipments) {
        String equipmenIdJson = "[";
        for (SysStationEquipment sysStationEquipment : SysStationEquipments) {
            equipmenIdJson += "设备:"+sysStationEquipment.getEquipmentId()+"-站点:"+sysStationEquipment.getStationId() + ",";
        }
        equipmenIdJson = equipmenIdJson.substring(0, equipmenIdJson.length() - 1) + "]";
        return equipmenIdJson;
    }
}
